﻿using System.Windows;
using System.Windows.Controls;

namespace Waaahsabi.Controls.TheGame
{
	public class GenericSelectorButton : Control
	{
		#region ItemName DependencyProperty
		public static readonly DependencyProperty ItemNameProperty =
		DependencyProperty.Register
			(
			"ItemName",
			typeof(string),
			typeof(GenericSelectorButton),
			new PropertyMetadata("Itemname not set")
			);

		public string ItemName
		{
			get { return (string)GetValue(ItemNameProperty); }
			set { SetValue(ItemNameProperty, value); }
		}
		#endregion
		#region ItemInterfaceId DependencyProperty
		public static readonly DependencyProperty ItemIdProperty =
		DependencyProperty.Register
			(
			"ItemInterfaceId",
			typeof(ulong),
			typeof(GenericSelectorButton),
			new PropertyMetadata(null)
			);

		public ulong ItemInterfaceId
		{
			get { return (ulong)GetValue(ItemIdProperty); }
			set { SetValue(ItemIdProperty, value); }
		}
		#endregion
		#region FeatureId DependencyProperty
		public static readonly DependencyProperty FeatureIdProperty =
		DependencyProperty.Register
			(
			"FeatureId",
			typeof(ulong),
			typeof(GenericSelectorButton),
			new PropertyMetadata(null)
			);

		public ulong FeatureId
		{
			get { return (ulong)GetValue(FeatureIdProperty); }
			set { SetValue(FeatureIdProperty, value); }
		}
		#endregion

		#region IsAccessible DependencyProperty
		public static readonly DependencyProperty IsAccessibleProperty =
		DependencyProperty.Register
			(
			"IsAccessible",
			typeof(bool),
			typeof(GenericSelectorButton),
			new PropertyMetadata(true)
			);

		public bool IsAccessible
		{
			get { return (bool)GetValue(IsAccessibleProperty); }
			set { SetValue(IsAccessibleProperty, value); }
		}
		#endregion


		public event RoutedEventHandler Click;
		private Button _btnSelectButton;
		public GenericSelectorButton()
		{
			DefaultStyleKey = typeof(GenericSelectorButton);
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			_btnSelectButton = GetTemplateChild("btnSelectButton") as Button;
			if (_btnSelectButton != null)
				_btnSelectButton.Click += (s, e) =>
				{
					if (Click != null)
						Click(this, e);
				};
		}
	}
}
